package st.business.tepth.business.goodscheck;

import android.view.View;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.chad.library.adapter.base.entity.MultiItemEntity;

import java.util.List;

import st.business.tepth.R;
import st.business.tepth.business.bean.MaterialCheckBean;
import st.business.tepth.business.bean.PickGoods;
import st.business.tepth.business.goodscheck.entity.Level0;
import st.business.tepth.business.goodscheck.entity.Level1;

/**
 * @author zhangyu
 * @date 2019/2/23
 */
public class GoodsCheckAdapter extends BaseMultiItemQuickAdapter<MultiItemEntity, BaseViewHolder> {
    public static final int TYPE_LEVEL_0 = 0;
    public static final int TYPE_LEVEL_1 = 1;

    /**
     * Same as QuickAdapter#QuickAdapter(Context,int) but with
     * some initialization data.
     *
     * @param data A new list is created out of this one to avoid mutable list
     */
    public GoodsCheckAdapter(List<MultiItemEntity> data) {
        super(data);
        addItemType(TYPE_LEVEL_0, R.layout.item_goods_check_operator);
        addItemType(TYPE_LEVEL_1, R.layout.item_goods);
    }


    @Override
    protected void convert(final BaseViewHolder helper, MultiItemEntity item) {
        switch (helper.getItemViewType()) {
            case TYPE_LEVEL_0:
                final Level0 lv0 = (Level0) item;
                MaterialCheckBean goodsOrderBean = lv0.getGoodsOrderBean();
                helper.setText(R.id.tv_apply_time, goodsOrderBean.getGmtCreate());
                helper.setText(R.id.tv_apply_person, goodsOrderBean.getApplyPerson());
                helper.setText(R.id.tv_leave_time, goodsOrderBean.getLeaveTime());
                helper.setText(R.id.tv_bus_number, goodsOrderBean.getVehicleNumber());
                helper.setText(R.id.tv_apply_goods, goodsOrderBean.getMaterialName());
                helper.setText(R.id.tv_type, getType(goodsOrderBean.getType()));
                helper.setText(R.id.tv_materials_state, goodsOrderBean.isWaitApply() ? "是" : "否");
                helper.setVisible(R.id.layout_operation, goodsOrderBean.getStatus() < 3);
                helper.setText(R.id.tv_goods_receive_state, goodsOrderBean.getStatusName());
                helper.getView(R.id.tv_apply_goods).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        int pos = helper.getAdapterPosition();
                        if (lv0.isExpanded()) {
                            collapse(pos);
                        } else {
                            expand(pos);
                        }
                    }
                });
                helper.addOnClickListener(R.id.tv_no_pass);
                helper.addOnClickListener(R.id.tv_pass);
                break;
            case TYPE_LEVEL_1:
                Level1 level1 = (Level1) item;
                PickGoods goodsBean = level1.getGoodsBean();
                helper.setText(R.id.tv_goods_name, goodsBean.getMaterialName());
                helper.setText(R.id.tv_brand, "品牌:" + goodsBean.getBrand());
                helper.setText(R.id.tv_version, "型号:" + goodsBean.getModelNo());
                helper.setText(R.id.tv_specification, "规格:" + goodsBean.getSpecifications());
                helper.setText(R.id.tv_batch, "批次号:" + goodsBean.getBatchNo());
                helper.setText(R.id.tv_shelf_number, "自编号:" + goodsBean.getShelfNo());
                helper.setText(R.id.tv_count, goodsBean.getValue() + goodsBean.getUnit());
                break;
        }
    }

    public String getType(int type) {
        String str = "";
        switch (type) {
            case 1:
                str = "小修";
                break;
            case 2:
                str = "一级保养";
                break;
            case 3:
                str = "二级保养";
                break;
            case 4:
                str = "三级保养";
                break;
        }
        return str;
    }

}
